class_name GameplayAbility
## Gameplay Ability
## Version: 0.1.0

## 能力是否激活
var active: bool = true

## 能力的资源类
var ability_asset: GameplayAbilityAsset

## 能力的拥有者
var owner: AbilitySystemComponent


func _init(init_ability_asset: GameplayAbilityAsset, init_owner: AbilitySystemComponent) -> void:
	ability_asset = init_ability_asset
	owner = init_owner


func can_activate() -> bool:
	var result1 = not ability_asset.tags_all_required or owner.tag_manager.has_all_tags(ability_asset.tags_all_required)
	var result2 = not ability_asset.tags_cancelled_ability or not owner.tag_manager.has_any_tags(ability_asset.tags_cancelled_ability)
	
	return true if (active and result1 and result2) else false


func activate(target: AbilitySystemComponent) -> void:
	for effect_asset: GameplayEffectAsset in ability_asset.granted_effects:
		target.apply_effect(effect_asset.create_spec(owner, target))

	_activate(target)
	

#region Need to override
func _activate(_target: AbilitySystemComponent) -> void:
	pass
#endregion
